package wifiunion.com.notice.presenter;

import android.content.Context;


import java.util.HashMap;

import wifiunion.com.notice.Constants;
import wifiunion.com.notice.NoticeContact;
import wifiunion.com.notice.NoticeModel;
import wifiunion.com.notice.utils.SharedPreferencesUtils;

/**
 * Created by Administrator on 2016/12/4.
 */

public class NoticeRelDeviceGroupListPresenter implements NoticeContact.Presenter, NoticeContact.Callback {

    private NoticeContact.View mView;
    private Context mContext;
    private NoticeModel mModel;

    private int mType;

    public NoticeRelDeviceGroupListPresenter(Context context, NoticeContact.View view) {
        mView = view;
        mContext = context;
        mModel = new NoticeModel();
        mView.setPresenter(this);
    }

    public void setType(int type)
    {
        this.mType = type;
    }

    @Override
    public void onSuccess(Object data) {


        mView.onGetNoticeDeviceGroupListSuccess(data);
    }

    @Override
    public void onServerFailed(Object errorObj) {
        mView.onError(errorObj);
    }

    @Override
    public void onNetFailed() {
        mView.onError("网络异常");
    }

    @Override
    public void start() {
        HashMap<String, Object> params = new HashMap<>();
        params.put("Authorization", SharedPreferencesUtils.getSharedPreferences(Constants.CONFIG_AUTHTOKEN, mContext));
        mModel.loadData(Constants.HTTP_URL_GET_RLDEVICEGROUPLIST, params, this);
    }

    @Override
    public void start(HashMap<String, Object> param1s) {

        if(mType == 0)
        {
            mModel.getRlGroup(Constants.HTTP_URL_GET_NOTICERLDEVICEGROUPLIST, param1s, this);
        }else if(mType == 1)
        {
            mModel.getRlGroup(Constants.HTTP_URL_GET_PATROLDEVICEGROUPLIST, param1s, this);
        }
        else if(mType == 2)
        {
            mModel.getRlGroup(Constants.HTTP_URL_GET_EXPOSUREDEVICEGROUPLIST, param1s, this);
        }
    }
}

